package com.smh.a09Test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {

        ServerSocket ss = new ServerSocket(10001);

        Socket accept = ss.accept();

        InputStream is = accept.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);

        FileOutputStream fos = new FileOutputStream("day30-code\\file\\b.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int b;
        while ((b = bis.read()) != -1) {
            bos.write((char) b);
            System.out.println((char) b);
        }
        bos.flush();
        bos.close();
//        accept.shutdownInput();//这只是给一个标志,不会关流
//        bis.close();


        //向客户端返回数据
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        String s = "年后在说";
        bw.write(s);
        bw.newLine();
        bw.flush();
        bw.close();


        accept.close();
        ss.close();


    }
}
